package com.wujing.demo;

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

/**
 * java11 发送http 请求
 */
public class DemoTest {

    public static void main(String[] args) throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        URI uri = URI.create("http://apis.juhe.cn/simpleWeather/query?city=%E5%8C%97%E4%BA%AC&key=da49ed5d4a5ecd4e4b20cad62ca16e6d");
        HttpRequest request = HttpRequest
                .newBuilder(uri)
                .GET()
                .build();
        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        String body = response.body();
        System.out.println(body);
    }
}
